<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.CommonUtil" %>
<%@ page import="java.util.List" %>
<%@ page import="com.wlcorp.forcazamis.domain.pi.PiproductDetail" %>
<%@ page import="com.wlcorp.forcazamis.domain.pi.Pifitting" %>
<%@ page import="com.wlcorp.forcazamis.domain.pi.Pidetail" %>
<%@ page import="com.wlcorp.forcazamis.domain.baseinfo.Factory" %>

<%
	Pidetail pidetail = (Pidetail)request.getAttribute("pidetail");
	List piproductList = (List)request.getAttribute("piproductList");
	List pifittingList = (List)request.getAttribute("pifittingList");
	List factoryList = (List)request.getAttribute("factoryList");
%>
<html>
<head>
	<title>PI生成采购合同</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Expires" content="0">
	<link href="${pageContext.request.contextPath}/css/css.css" rel=stylesheet>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/button_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/table_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagetitle_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/basic.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/tabs.css" type="text/css">
	<script language="javascript" src="${pageContext.request.contextPath}/script/validator.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/calendartime.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/ajax.js"></script>
	
	<script type="text/javascript">
	function doSave(){
		document.getElementById("productForm").action="${pageContext.request.contextPath}/pi/pidetailManager.do?method=stockProductBuild&piid="+<%=pidetail.getPiid()%>;
		document.getElementById("productForm").submit();
		//document.forms["productForm"].action="${pageContext.request.contextPath}/pi/pidetailManager.do?method=stockProductBuild&piid="+<%=pidetail.getPiid()%>;
		//document.forms["productForm"].submit();
	}
	
	function doSave2(){
		document.getElementById("fittingForm").action="${pageContext.request.contextPath}/pi/pidetailManager.do?method=stockFittingBuild&piid="+<%=pidetail.getPiid()%>;
		document.getElementById("fittingForm").submit();
	}
	
	function checkAll() {
  		for (var i = 0; i < document.getElementsByName("selectFlag").length; i++) {
   			document.getElementsByName("selectFlag")[i].checked = document.getElementById("ifAll").checked;
  	 }
 	}
 	
 	function checkAll2() {
  		for (var i = 0; i < document.getElementsByName("selectFlag2").length; i++) {
   			document.getElementsByName("selectFlag2")[i].checked = document.getElementById("ifAll2").checked;
  	 }
 	}
 	
 	  
 	function showProductDiv(){
 	  var productDiv=document.getElementById("productDiv");   
	  var fittingDiv=document.getElementById("fittingDiv");   
	  if(productDiv.style.display=="none"){
	    productDiv.style.display="";
	    fittingDiv.style.display="none";
	  }
	  if(productDiv.style.display==""){
	    fittingDiv.style.display="none";
	  }
	}
	
	function showFittingDiv(){
	  var productDiv=document.getElementById("productDiv");   
	  var fittingDiv=document.getElementById("fittingDiv");   
	  if(fittingDiv.style.display=="none"){
	    fittingDiv.style.display="";
	    productDiv.style.display="none";
	  }
	  if(fittingDiv.style.display==""){
	    productDiv.style.display="none";
	  }
	}
	</script>
</head>
<body>
<div id="header">
		<ul id="primary">
			<li><a href="javascript:void(0)" onClick="showProductDiv();"><b>PI产品导出</b></a></li>
			<li><a href="javascript:void(0)" onClick="showFittingDiv();"><b>PI配件导出</b></a></li>
		</ul>
</div>
<center>

<table width="90%" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="80">
  <tr> 
    <td colspan="8" class="table_unfold_titlebar_small_bg">&nbsp;&nbsp;<b>销售合同基本信息</b></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="15%">合同编号：</td>
		<td width="18%" colspan="3">${pidetail.piCode}</td>
		
		<td class="table_label" width="15%">下单日期：</td>
		<td width="18%">${pidetail.piDate}</td>
		
		<td class="table_label" width="15%">最迟出运日：</td>
		<td width="18%">${pidetail.outDate}</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="15%">客户名称：</td>
		<td width="40%" colspan="5">${pidetail.customer.customerFullName}</td>
		
		<td class="table_label" width="15%">客户定单号：</td>
		<td width="30%">${pidetail.customerOgCode}</td>
  </tr>
</table>


<div id="productDiv" style="display:">
<form name="productForm" method="post">
<input type="hidden" name="piid" value="<%=pidetail.getPiid()%>"/>
<input class=button_save type=button name=save value="      保存" style="font-size:9pt" onClick="javascript:doSave()">&nbsp;&nbsp;&nbsp;
<input type=button name=rst class=button_recovery value="     返回" style="font-size:9pt" onClick="javascript:history.go(-1);" id="btn_recovery">
<table id="" width="90%" border="0" cellspacing="1" cellpadding="0" bgcolor="#999999">
	  <tbody id="piproductTable">
      <tr bgcolor="#E7E7E7">
      	<td><input type="checkbox" name="ifAll" id="ifAll" value="全选" onClick="checkAll()"></td>
        <td>客户货号</td>
        <td>我司型号</td>
        <td>尺寸</td>
        <td>颜色</td>
        <td>数量</td>
        <td>销售单价</td>
         <td>供应商(请选择<font color="red">*</font>)</td>
      </tr>
      <%
      	if(null != piproductList&&piproductList.size()>0){
      		for(Iterator iter = piproductList.iterator();iter.hasNext();){
      			PiproductDetail piproductDetail = (PiproductDetail)iter.next();
      			
      %>
      <tr id="<%=piproductDetail.getProductId()%>" bgcolor="#ffffff">
      	<td><input type="checkbox" name="selectFlag" value="<%=piproductDetail.getProductId()%>"/></td>
      	<td><%=piproductDetail.getCustProdCode()%></td>
        <td><%=piproductDetail.getSubSample().getParentSample().getSampleCode()%></td>
        <td><%=CommonUtil.nullToStr(piproductDetail.getSize())%></td>
        <td><%=CommonUtil.nullToStr(piproductDetail.getEcolor())%> <%=piproductDetail.getColor()%></td> 
        <td><%=piproductDetail.getProdCount()%></td>
        <td><%=piproductDetail.getPrice()%></td>
 		<td>
			<select name="factory">
			    <option value="0">--请选择--</option>
				<%
				if(null!=factoryList&&factoryList.size()>0){
					for(int i=0;i<factoryList.size();i++){
						Factory factory=(Factory)factoryList.get(i);
				%>
				<option value="<%=factory.getFactoryId()%>"><%=factory.getFactoryCode()%> - <%=factory.getFactoryFullName()%></option>
				<%}} %>
			</select>
		</td>
	  </tr>
	  <%}}%>
	  </tbody>
</table>
</form>
</div>


<div id="fittingDiv" style="display:none">
<form name="fittingForm" method="post">
<input type="hidden" name="piid2" value="<%=pidetail.getPiid()%>"/>
<input class=button_save type=button name=save2 value="      保存" style="font-size:9pt" onClick="javascript:doSave2()">&nbsp;&nbsp;&nbsp;
<input type=button name=rst class=button_recovery value="     返回" style="font-size:9pt" onClick="javascript:history.go(-1);" id="btn_recovery">
<table id="" width="90%" border="0" cellspacing="1" cellpadding="0" bgcolor="#999999">
	  <tbody id="piproductTable2">
      <tr bgcolor="#E7E7E7">
      	<td><input type="checkbox" name="ifAll2" id="ifAll2" value="全选" onClick="checkAll2()"></td>
        <td>英文品名</td>
        <td>英文规格</td>
        <td>数量</td>
        <td>单价</td>
        <td>金额</td>
        <td>供应商(请选择<font color="red">*</font>)</td>
      </tr>
      <%
      	if(null != pifittingList&&pifittingList.size()>0){
      		for(Iterator iter = pifittingList.iterator();iter.hasNext();){
      			Pifitting pifitting = (Pifitting)iter.next();
      			
      %>
      <tr id="<%=pifitting.getFittingId()%>" bgcolor="#ffffff">
      	<td><input type="checkbox" name="selectFlag2" value="<%=pifitting.getFittingId()%>"/></td>
      	<td><%=pifitting.getEname()%></td>
        <td><%=pifitting.getEspec()%></td>
        <td><%=pifitting.getFittingCount()%></td>
        <td><%=pifitting.getUnitPrice()%></td> 
        <td><%=pifitting.getTotalSum()%></td>
 		<td>
			<select name="factory2">
			    <option value="0">--请选择--</option>
				<%
				if(null!=factoryList&&factoryList.size()>0){
					for(int i=0;i<factoryList.size();i++){
						Factory factory=(Factory)factoryList.get(i);
				%>
				<option value="<%=factory.getFactoryId()%>"><%=factory.getFactoryCode()%> - <%=factory.getFactoryFullName()%></option>
				<%}} %>
			</select>
		</td>
	  </tr>
	  <%}}%>
	  </tbody>
</table>
</form>
</div>

<center>
${message}
</body>
</html>